<template>
    <div class="risk">
        <eagle-page-list ref="eaglePageList" @bindData="bindData" :queryParams="queryParams" :controller="controller"
            placeholder="请输入化学品名称搜索" :conditions="conditions" :pageSize="20">
            <div slot="list">
                <eagle-cell class="card" style="margin-top: 10px" v-for="(item, index) in list" :key="index">
                    <eagle-tag v-if="item.CheckResult == 'N'" class="info_tag" color="#f25536">不符合</eagle-tag>
                    <eagle-tag v-if="item.CheckResult == 'Y'" class="info_tag" color="#00bfdc">符 合</eagle-tag>
                    <eagle-tag v-if="item.CheckResult == 'Na'" class="info_tag" color="#f4ad55">不适用</eagle-tag>

                    <div class="warn_item">
                        <div @click="goDetail(item)">
                            <div class="warn_header">
                                <div>
                                    {{ index + 1 }}、隐患描述：{{ item.HiddenDangerDesc }}
                                </div>

                            </div>
                            <!-- <div class="dep_sort">
                <img src="@/assets/Images/AppIcon/icon_list_org.png" alt="" />
                <div>{{ item.CheckTypeName }}</div>
              </div> -->
                            <eagle-row gutter="20" class="dep_sort">
                                <eagle-col span="24">
                                    <img src="@/assets/Images/AppIcon/icon_list_org.png" alt="" />所属任务：{{
            item.CheckTaskName }}</eagle-col>
                            </eagle-row>

                            <eagle-row gutter="20" class="dep_sort">
                                <eagle-col span="12">
                                    <img src="@/assets/Images/AppIcon/icon_list_post.png" alt="" />{{
            item.OriginType == 1
                ? "检查表检查"
                : item.OriginType == 2
                    ? "依据检查"
                    : "随手拍"
        }}</eagle-col>
                            </eagle-row>
                            <eagle-row gutter="20" class="dep_sort">
                                <eagle-col span="12">
                                    <img src="@/assets/Images/AppIcon/icon_list_kind.png" alt="" />{{
                item.LGDFullName
            }}</eagle-col>
                            </eagle-row>
                            <eagle-row class="dep_sort">
                                <eagle-col span="8">
                                    <img src="@/assets/Images/AppIcon/icon_list_security.png" alt="" />{{
                                    item.CreateChnName }}</eagle-col>
                                <eagle-col span="16">
                                    <img src="@/assets/Images/AppIcon/icon_list_security.png" alt="" />{{
                                    item.CreateDate }}</eagle-col>
                            </eagle-row>
                            <eagle-row gutter="20" class="dep_sort">
                                <eagle-col >
                                    <img src="@/assets/Images/AppIcon/icon_list_type.png" alt="" />状态 :&nbsp {{item.StatusName}}</eagle-col>
                            </eagle-row>
                        </div>
                    </div>
                    <div :class="status==20?'dep_btm':'dep_btm2'">
                        
                        <div v-if="status==20" class="btm_item" @click="handleCopy(item)">
                            <img src="@/assets/Images/AppIcon/icon_list_copy.png" alt="" />
                            <div class="mr-10">复制该记录</div>
                        </div>
                        <div class="btm_item" @click="handledelete(item)">
                            <img src="@/assets/Images/AppIcon/icon_delete.png" alt="" />
                            <div class="mr-10">删除该记录</div>
                        </div>
                    </div>
                </eagle-cell>
            </div>
        </eagle-page-list>

    </div>
</template>
<script>
import { Dialog } from "vant";
import {getStatusText} from  '@/api/base'
export default {
    data() {
        return {
            controller: '/DangerCheckTaskDetailJG/GetPageData',
            queryParams: {
                // dataType: "TaskDetail",
                // dataType: "DangerDetail",
                dataType: "DangerDetail",
                keywords: "",
                ctCode: ''
            },
            ctCode: '',
            status:'',
            list: [],
            isJG:false

        }
    },
    created() {
        this.ctCode = this.$route.query.ctCode;
        this.status = this.$route.query.status;
        this.queryParams.ctCode = this.ctCode;
        this.isJG=this.$route.query.isJG;
        if(this.$route.query.dataType){
            this.queryParams.dataType=this.$route.query.dataType
        }

    },

    methods: {
        bindData(data) {
            this.list = data;
            this.list.forEach(element => {
                
                let StatusText=getStatusText(element.Status)
                element.StatusName=VerifyTimes==0?StatusText:StatusText+'(验收次数:'+VerifyTimes+')'
                
            });
        },
        goDetail(item) {

            //编辑随手拍
            if (item.CheckResult == 'N' && item.Status <= 20) {
                this.$router.push({
                    path: "/Danger/DangerCheckTaskDetailEdit_JG",
                    // path: "/Danger/DangerCheckTaskDetailEdit",
                    query: { originType: 2, id: item.ID,ctCode:this.ctCode },
                });

            } else if (item.Status > 30) {
                if(this.isJG){
                    this.$router.push({
                        path: "/Danger/DangerCheckTaskDetailVerifyDetail_JG",
                        query: { id: item.ID },
                    });
                }else{
                    this.$router.push({
                    path: "/Danger/DangerCheckTaskDetailVerifyDetail",
                    query: { id: item.ID },
                });
                }
        

            }

            else {
                this.$router.push({
                    path: "/Danger/DangerCheckTaskEdit",
                    query: { id: item.ID },
                });
            }

        },
        handledelete(item) {
            let _this = this;
            Dialog.confirm({
                title: "询问",
                message: "你确定要删除该检查记录吗?",
            })
                .then(() => {
                    // on confirm
                    _this.$axios
                        .get("/DangerCheckTaskDetailJG/DeleteTaskDetail", { params: { id: item.ID } })
                        .then((res) => {
                            _this.$toast.success("删除成功！");
                            console.log('执行前');
                            _this.$refs.eaglePageList.getList();
                            console.log('执行后');
                        });
                })
                .catch(() => {
                    // on cancel
                })
        },
        handleCopy(item){
            let _this = this;
            Dialog.confirm({
                title: "询问",
                message: "你确定要复制该检查记录吗?",
            })
                .then(() => {
                    // on confirm
                    _this.$axios
                        .get("/DangerCheckTaskDetail/CopyDanger", { params: { id: item.ID } })
                        .then((res) => {
                            _this.$toast.success("复制成功");
                 
                            _this.$refs.eaglePageList.getList();
                        
                        });
                })
                .catch(() => {
                    // on cancel
                })
        },
    }


}
</script>
<style lang="less">
.risk {
    background-color: #e8f1f8;

    .info_search {
        padding: 10px;
        border-radius: 5px !important;

        .van-field__control {
            background-color: #ffffff !important;
        }
    }
}

.all_dep {
    background-color: #ffffff;
}

.warn_header {
    display: flex;
    justify-content: space-between;
    position: relative;
    margin-bottom: 10px;

    .warn_tag {
        position: absolute;
        right: 0;
        top: 0;
        border-radius: 26.64rem 0 0 26.64rem;
    }
}

.dep_sort {

    // display: flex;
    // flex-wrap: wrap;
    // margin-bottom: 5px;
    img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
    }
}

.dep_btm {
    display: flex;
    justify-content: space-between;

    .btm_item {
        display: flex;
        align-items: center;

        img {
            height: 15px;
            width: 15px;
            margin-right: 5px;
        }
    }
}
.dep_btm2 {
    display: flex;
    justify-content: flex-end;

    .btm_item {
        display: flex;
        align-items: center;

        img {
            height: 15px;
            width: 15px;
            margin-right: 5px;
        }
    }
}
.choose_btm {
    display: flex;
    width: 100%;
    justify-content: space-between;
    position: fixed;
    bottom: 0;
    background-color: #fff;

    .choose_cancel {
        padding: 0 10px;
        display: flex;
        align-items: center;
        float: left;
    }

    .choose_confirm {
        float: right;
        border-radius: 0;
    }
}
</style>